package org.codefinger.dao.impl.sql.ast;

import org.codefinger.dao.impl.SQLVisitor;
import org.codefinger.dao.impl.sql.Expression;
import org.codefinger.dao.util.Lang;

public class AliasExpression implements Expression {

	private Expression	exp;

	private String		suffix;

	public AliasExpression(Expression exp, String alias) {
		super();
		this.exp = exp;
		this.suffix = Lang.joinStr(alias.length() + 1, " ", alias);
	}

	@Override
	public boolean matchVisit(SQLVisitor visitor) {
		if (exp.matchVisit(visitor)) {
			visitor.appendSQL(suffix);
			return true;
		}
		return false;
	}

	@Override
	public void visit(SQLVisitor visitor) {
		exp.visit(visitor);
		visitor.appendSQL(suffix);
	}
	
}
